// 基本关系图

// eslint-disable-next-line complexity
export default function getBasicRelation(optionSet = { links: [], nodes: [] }) {
  const graph = {
    links: [],
    nodes: []
  };
  if (optionSet.links) {
    optionSet.links.forEach(i => {
      graph.links.push({
        target: i.id,
        source: i.source
      });
    });
  }
  if (optionSet.nodes) {
    optionSet.nodes.forEach(i => {
      graph.nodes.push({
        attributes: { modularityClass: 0 },
        category: parseInt(i.category),
        draggable: true,
        id: i.id,
        itemStyle: null,
        name: i.name,
        symbolSize: 10,
        value: i.value,
        x: null,
        y: null
      });
    });
  }

  const categories = graph.nodes.map(i => {
    return {
      name: i.name
    };
  });
  const option = {
    title: {
      text: 'Les Miserables',
      subtext: 'Default layout',
      top: 'bottom',
      left: 'right'
    },
    tooltip: {},
    legend: [
      {
        // selectedMode: 'single',
        data: categories.map(function(a) {
          return a.name;
        })
      }
    ],
    animation: false,
    series: [
      {
        name: 'Les Miserables',
        type: 'graph',
        layout: 'force',
        data: graph.nodes,
        links: graph.links,
        categories: categories,
        roam: true,
        label: {
          normal: {
            position: 'right'
          }
        },
        force: {
          repulsion: 100
        }
      }
    ]
  };
  return option;
}
